Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Min tokens in token limiter #2400

Merged
merged 20 commits into from
Apr 29, 2024

Conversation

giorgossideris
Copy link
Collaborator

@giorgossideris giorgossideris commented Apr 16, 2024

Why are these changes needed?

A min_tokens_threshold is added to MessageTokenLimiter, which gives the option to cut tokens only after the specified message limit is reached.

Related issue number

Closes #2306.

Checks

@codecov-commenter
Copy link

codecov-commenter commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 33.50%. Comparing base (ded2d61) to head (6b05ab3).
Report is 7 commits behind head on main.

Files Patch % Lines
...togen/agentchat/contrib/capabilities/transforms.py 0.00% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2400      +/-   ##
==========================================
+ Coverage   33.33%   33.50%   +0.17%     
==========================================
  Files          83       81       -2     
  Lines        8636     8741     +105     
  Branches     1835     1868      +33     
==========================================
+ Hits         2879     2929      +50     
- Misses       5516     5564      +48     
- Partials      241      248       +7     
Flag Coverage Δ
unittests 33.50% <0.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WaelKarkoub
Copy link
Contributor

WaelKarkoub commented Apr 16, 2024

@giorgossideris Thanks for the PR! min_tokens_threshold makes sense for MessageTokenLimiter. Like we discussed before, MessageHistoryLimiter shouldn't concern itself with the number of tokens to avoid overlap in responsibilities.

@giorgossideris giorgossideris changed the title Min tokens in history limiter Min tokens in token limiter Apr 17, 2024
Copy link
Contributor

@WaelKarkoub WaelKarkoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is shaping up nicely

autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
@WaelKarkoub
Copy link
Contributor

Just a reminder to update the guide and notebook

@giorgossideris
Copy link
Collaborator Author

@WaelKarkoub I made the discussed changes, although there are two points that concern me:

  1. About the min_tokens < max_tokens condition: what if the user wants to set min_tokens to the max token limit of the model?
  2. (Not really related to this PR) Notebook and website docs are not aligned (same idea but different structure). I am not sure if this is something that we want to avoid.

Copy link
Contributor

@WaelKarkoub WaelKarkoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes! A couple more looks and this is mergeable.

  1. Your current validator makes sense. min_tokens <= max_tokens
  2. No need for a major rewrite, just a simple demonstration of how min_tokens works is enough

notebook/agentchat_transform_messages.ipynb Show resolved Hide resolved
notebook/agentchat_transform_messages.ipynb Show resolved Hide resolved
website/docs/topics/long_contexts.md Outdated Show resolved Hide resolved
website/docs/topics/long_contexts.md Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
autogen/agentchat/contrib/capabilities/transforms.py Outdated Show resolved Hide resolved
@giorgossideris
Copy link
Collaborator Author

@WaelKarkoub I made the requested changes.

Copy link
Contributor

@WaelKarkoub WaelKarkoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

Copy link

gitguardian bot commented Apr 22, 2024

⚠️ GitGuardian has uncovered 5 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- Generic High Entropy Secret 899c472 test/oai/test_utils.py View secret
- Generic CLI Secret df20e0b .github/workflows/dotnet-release.yml View secret
- Generic High Entropy Secret 899c472 test/oai/test_utils.py View secret
- Generic High Entropy Secret 899c472 test/oai/test_utils.py View secret
- Generic High Entropy Secret 899c472 test/oai/test_utils.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@WaelKarkoub WaelKarkoub requested a review from ekzhu April 23, 2024 17:35
@giorgossideris
Copy link
Collaborator Author

Hello @ekzhu, do you want me to do anything related to the failed test?

@sonichi sonichi added this pull request to the merge queue Apr 29, 2024
Merged via the queue into microsoft:main with commit 11a4342 Apr 29, 2024
68 of 82 checks passed
jayralencar pushed a commit to jayralencar/autogen that referenced this pull request May 28, 2024
* Add minimum token threshold in MessageHistoryLimiter

* Update transforms tests for the threshold

* Move min_threshold_tokens from Message to Token Limiter

* Optimize _check_tokens_threshold

Co-authored-by: Wael Karkoub <wael.karkoub96@gmail.com>

* Apply requested changes (renaming, phrasing, validations)

* Fix format

* Fix _check_tokens_threshold logic

* Update docs and notebook

* Improve phrasing

* Add min_tokens example in notebook

* Add min_tokens example in website docs

* Add min_tokens example in notebook

* Update website docs to be in sync with get_logs change

---------

Co-authored-by: Wael Karkoub <wael.karkoub96@gmail.com>
Co-authored-by: Chi Wang <wang.chi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: MessageTransform when token limit is exceeded.
6 participants